package com.baosight.sczx.zm.ct.service;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.zm.ct.domain.ZMCTSmsModelCreatetime;

/**
 * 
 * <p>Title: ServiceZMCT21.java</p>
 * <p>Description: 发送时间管理</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author wangkun
 * @version 1.0
 * <pre>Histroy:
 *          2012-6-29 上午10:36:12  wangkun  Create
 *</pre>
 */
public class ServiceZMCT21 extends ServiceEPBase 
{
	public EiInfo initLoad(EiInfo inInfo)
	{
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);

		if(outInfo.getBlock(EiConstant.resultBlock).getRowCount()!=0)
		{
			outInfo.set("mode", "update");
		}else
		{
			outInfo.set("mode", "insert");
		}
		
		return outInfo;
	}
	
	public EiInfo query(EiInfo inInfo)
	{
		StaticTools.setQueryParameters(inInfo, "fdModelId", inInfo.get("fdModelId"), true);//添加查询条件
		EiInfo outInfo = super.query(inInfo, "ZMCTSmsModelCreatetime.query", new ZMCTSmsModelCreatetime());
		
		return outInfo;
	}
	
	public EiInfo insert(EiInfo inInfo)
	{
		inInfo.getBlock("result").setCell(0, "fdKeyId", TablePk.getInstance().getNextValue("T_CT_SMS_MODEL_CREATETIME"));//主键
		
		EiInfo _temp = super.insert(inInfo, "ZMCTSmsModelCreatetime.insert");
		if(_temp.getStatus() != -1)
		{
			_temp = super.insert(inInfo, "ZMCTSmsModelSendtime.insert");
		}
		EiInfo outInfo = this.query(inInfo);
		outInfo.setMsg(_temp.getMsg());
		outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}
	
	public EiInfo update(EiInfo inInfo)
	{
		EiInfo outInfo = super.update(inInfo, "ZMCTSmsModelCreatetime.update");
		
		if(outInfo.getStatus() != -1)
		{
			outInfo = super.insert(inInfo, "ZMCTSmsModelSendtime.update");
		}
		return outInfo;
	}
}
